package de.schlinke_marius.dialogs;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ZoomControls;

import com.actionbarsherlock.app.SherlockDialogFragment;

import de.schlinke_marius.R;
import de.schlinke_marius.activities.ExamplesDetail;
import de.schlinke_marius.data.FragmentConstants;
import de.schlinke_marius.views.TouchImageView;

public class BigPictureDialog extends SherlockDialogFragment implements FragmentConstants {

	/*
	 * UI elements
	 */
	private TouchImageView ivDetailPicture = null;
	private ZoomControls czImageControls = null;

	private ExamplesDetail activity = null;

	public static BigPictureDialog newInstance(Bundle bundle) {

		BigPictureDialog bigPictureDialog = new BigPictureDialog();
		bigPictureDialog.setArguments(bundle);
		return bigPictureDialog;
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		this.activity = (ExamplesDetail) activity;
	}

	@Override
	public void onCreate(Bundle icicle) {
		setCancelable(true);
		setStyle(STYLE_NO_TITLE, R.style.Msc_Dialog);
		super.onCreate(icicle);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle) {
		View view = inflater.inflate(R.layout.dialog_big_picture, container, false);
		return view;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		// initialize View Components
		ivDetailPicture = (TouchImageView) view.findViewById(R.id.ivBigPicture);
		czImageControls = (ZoomControls) view.findViewById(R.id.zcImageControls);
		
		String uri = "drawable/" + getArguments().getString(BUNDLE_KEY_BIG_PICTURE);
		ivDetailPicture.setImageResource(activity.getResources().getIdentifier(uri, null, activity.getPackageName()));
		
		// register Component Listeners
		registerListeners();
	}

	/**
	 * register Component Listeners
	 */
	private void registerListeners() {
		// Zoom In Listener
		czImageControls.setOnZoomInClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ivDetailPicture.zoomIn((ivDetailPicture.getWidth() / 2), (ivDetailPicture.getHeight() / 2));
			}
		});
		
		// Zoom Out Listener
		czImageControls.setOnZoomOutClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ivDetailPicture.zoomOut((ivDetailPicture.getWidth() / 2), (ivDetailPicture.getHeight() / 2));
			}
		});
	}	

}
